/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelUser.java
 *
 * Created on 08-dic-2011, 17:20:12
 */
package edu.uoc.tdp.client;

import edu.uoc.tdp.entity.Resource;
import edu.uoc.tdp.entity.Booking;
import edu.uoc.tdp.entity.User;
import java.awt.Color;
import java.rmi.RemoteException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.AbstractTableModel;
import javax.swing.JComboBox;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.text.ParseException;
import javax.swing.JOptionPane;

/**
 *
 * @author tomeu
 */
public class PanelBookings extends javax.swing.JFrame {

    // private ManagementBookings remoteBookings;
    //private ManagementBookingResources remoteBookingResources;
    //private ManagementUsers remoteUsers;

    /** Creates new form PanelUser */
    public PanelBookings(Boolean Admin) {

        initComponents();

        /* Carregar texts de labels i botons
        btnSave.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNSAVE));
        btnCancel.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNCANCEL));
         */
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnCancel = new javax.swing.JButton();
        btnPay = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblBookingSpaces = new javax.swing.JTable();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        btnCancelBooking = new javax.swing.JButton();
        txtTotalAmount = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jButtonFilter = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jtxtFrom = new javax.swing.JTextField();
        jcmbUser = new javax.swing.JComboBox();
        jtxtTo = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                WindowOpened(evt);
            }
        });

        btnCancel.setText("Tornar");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        btnPay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/accept.png"))); // NOI18N
        btnPay.setText("Pagar");
        btnPay.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnPayMouseClicked(evt);
            }
        });

        tblBookingSpaces.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Num Reserva", "Aula", "Data Inici", "Data Fi", "Hores", "Estat", "Import"
            }
        ));
        tblBookingSpaces.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblBookingSpacesMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tblBookingSpaces);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "RecursId", "Descripcio", "Preu"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        btnCancelBooking.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/cancel.png"))); // NOI18N
        btnCancelBooking.setText("Anular");
        btnCancelBooking.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnCancelBookingMouseClicked(evt);
            }
        });

        jLabel1.setText("Total");

        jButtonFilter.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/find.png"))); // NOI18N
        jButtonFilter.setText("Filter");
        jButtonFilter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFilterActionPerformed(evt);
            }
        });

        jLabel2.setText("Usuari");

        jcmbUser.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tots" }));

        jLabel4.setText("Hasta");

        jLabel3.setText("Entre");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btnPay, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnCancelBooking, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 133, Short.MAX_VALUE)
                                .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 573, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(6, 6, 6)
                                        .addComponent(txtTotalAmount, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel1))))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel3)
                                        .addComponent(jtxtFrom, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel4)
                                        .addComponent(jtxtTo, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(32, 32, 32)
                                    .addComponent(jButtonFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 573, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(681, 681, 681))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jcmbUser, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jcmbUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jButtonFilter)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jtxtFrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jtxtTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtTotalAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancel)
                    .addComponent(btnPay)
                    .addComponent(btnCancelBooking))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void WindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_WindowOpened

        try {
            // TODO add your handling code here:
         List <Booking> bookingsList = Client.remoteConnect.GetAllBookings();
            //List <Booking> bookingsList = Client.remoteMaintenance.GetAllBookings();
            edu.uoc.tdp.client.TableModelBookings model = new TableModelBookings(bookingsList);
            tblBookingSpaces.setModel(model);
            
         // Omplim dades combo Usuaris

            List<User> listaUsers;

            listaUsers = Client.remoteMaintenance.GetAllUser();
            cargarComboUsers(jcmbUser, listaUsers);
        } catch (RemoteException ex) {
            Logger.getLogger(PanelBookings.class.getName()).log(Level.SEVERE, null, ex);
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelBookings.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_WindowOpened

    /*
     * Carga la lista que se le envía por parámetro en el combo del parámetro
     */
    private void cargarComboUsers(JComboBox combo, List lista) {
        String item;
        String InactUser = null;
        for (Object obj : lista) {
            InactUser = ((User) obj).getInactivationUser();
            if (InactUser == null || InactUser == "") {
                InactUser = "";
            } else {
                InactUser = "  Inactiu!";
            }
            item = ((User) obj).getUserId() + " | " + ((User) obj).getName().trim() + InactUser;
            combo.addItem(item);
        }
    }

    private void tblBookingSpacesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblBookingSpacesMouseClicked
        // TODO add your handling code here:
        int fila = tblBookingSpaces.rowAtPoint(evt.getPoint());
        int columna = tblBookingSpaces.columnAtPoint(evt.getPoint());
        if ((fila > -1) && (columna > -1)) {
            try {
                // TODO add your handling code here:
                //remoteBookingResources = new ManagementBookingResources();
                //String bookingidString = (String)jTable2.getValueAt(fila, 0);
                Integer bookingid = (Integer) tblBookingSpaces.getValueAt(fila, 0); //Integer.parseInt(bookingidString.trim());
                List<Resource> resourcesList = Client.remoteConnect.GetOneBookingResources(bookingid);
                //set the entity objects in the list
                if (!resourcesList.isEmpty()) {
                    edu.uoc.tdp.client.TableModelResources model = new TableModelResources(resourcesList);
                    jTable1.setModel(model);
                } else {
                    //edu.uoc.tdp.client.TableModelResources model = (edu.uoc.tdp.client.TableModelResources) jTable1.getModel();
                    edu.uoc.tdp.client.TableModelResources model = new TableModelResources(resourcesList);
                    jTable1.setModel(model);
                    int a = model.getRowCount() - 1;
                    for (int i = 0; i < a; i--) {
                        //model.removeRow(i);
                    }
                }
                txtTotalAmount.setText(String.valueOf(Client.remoteConnect.CalcPrice(bookingid)));
                
            } catch (RemoteException ex) {
                Logger.getLogger(PanelBookings.class.getName()).log(Level.SEVERE, null, ex);
            } catch (edu.uoc.tdp.common.EIssueException ex) {
                Logger.getLogger(PanelBookings.class.getName()).log(Level.SEVERE, null, ex);
            }
            //JOptionPane.showMessageDialog(this, "User " + tblUsers.getValueAt(fila, 1), "User", JOptionPane.INFORMATION_MESSAGE);                
            //ShowUser(String.valueOf(jTable2.getValueAt(fila, 0)));
        }
    }//GEN-LAST:event_tblBookingSpacesMouseClicked

    private void btnPayMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnPayMouseClicked
        try {
            // TODO add your handling code here:
            int fila = tblBookingSpaces.rowAtPoint(evt.getPoint());
            Integer bookingid = (Integer) tblBookingSpaces.getValueAt(fila, 0);
            Client.remoteConnect.PayBooking(bookingid, Integer.parseInt(txtTotalAmount.getText()));
        } catch (Exception e) { //FIXME
            e.printStackTrace();
        }
    }//GEN-LAST:event_btnPayMouseClicked

    private void btnCancelBookingMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCancelBookingMouseClicked
        try {      
            
            int fila = tblBookingSpaces.rowAtPoint(evt.getPoint());
            Integer bookingid = (Integer) tblBookingSpaces.getValueAt(fila, 0);
            Client.remoteConnect.CancelBooking(bookingid, Client.availableUser.getUserId());//fixme
            JOptionPane.showMessageDialog(null, "Reserva Cancelada con éxito");
        } catch (RemoteException ex) {
            Logger.getLogger(PanelBookings.class.getName()).log(Level.SEVERE, null, ex);
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelBookings.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_btnCancelBookingMouseClicked

    private void jButtonFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFilterActionPerformed
        try {

            String user = "ALL";
            if (jcmbUser.getSelectedIndex() > 0) {
                String item = jcmbUser.getItemAt(jcmbUser.getSelectedIndex()).toString();
                int inicio = item.indexOf("|");
                user = item.substring(0, inicio - 1);
                //user= jcmbUser.getItemAt(jcmbUser.getSelectedIndex()).toString();
            }

            //Revisem Dates
            jtxtFrom.setBackground(Color.white);
            jtxtTo.setBackground(Color.white);
            SimpleDateFormat textDateFormat = new SimpleDateFormat("dd-MM-yyyy");
            Calendar calendar = Calendar.getInstance();

            String startTime = jtxtFrom.getText();
            String endTime = jtxtTo.getText();

            String todayStr = textDateFormat.format(calendar.getTime());
            Date today = Calendar.getInstance().getTime();


            try {
                textDateFormat.parse(startTime.trim());
            } catch (ParseException ex) {
                startTime = "1-1-1901";
                if (jtxtFrom.getText().length() > 0) {
                    jtxtFrom.setBackground(Color.red);
                }
            }

            try {
                textDateFormat.parse(endTime.trim());
            } catch (ParseException ex) {
                endTime = todayStr;
                if (jtxtTo.getText().length() > 0) {
                    jtxtTo.setBackground(Color.red);
                }
            }

            List<Booking> bookingsList;     
            bookingsList = Client.remoteConnect.GetAllBookings(user, startTime, endTime);
            //set the entity objects in the list
            edu.uoc.tdp.client.TableModelBookings model = new TableModelBookings(bookingsList);
            tblBookingSpaces.setModel(model);

        } catch (RemoteException ex) {
            Logger.getLogger(PanelBookings.class.getName()).log(Level.SEVERE, null, ex);
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
            //lblMessage.setText("Error" + ex.toString());
        }
    }
        // TODO add your handling code here:         try {             String user = jcmbUser.getItemAt(jcmbUser.getSelectedIndex()).toString();              List<Booking> bookingsList = remoteBookings.GetAllBookings();             //set the entity objects in the list             edu.uoc.tdp.client.TableModelBookings model = new TableModelBookings(bookingsList);             jTable2.setModel(model);         }     }          catch (EIssueException ex               ) 		{ 		Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);         //lblMessage.setText("Error" + ex.toString());     } }//GEN-LAST:event_jButtonFilterActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnCancelActionPerformed

    /*public void CalcTotalAmount(){
    int fila = jTable2.rowAtPoint(evt.getPoint());
    edu.uoc.tdp.client.TableModelResources model = (edu.uoc.tdp.client.TableModelResources) jTable1.getModel();
    int a =model.getRowCount()-1;
    for(int i=0; i<a;i--){
    //suma dels imports model.removeRow(i);
    }
    try {
    ManagementSpaces remoteSpaces = new ManagementSpaces();
    //String bookingidString = (String)jTable2.getValueAt(fila, 0);
    Integer Sid = (Integer) jTable2.getValueAt(fila, 0); //Integer.parseInt(bookingidString.trim());
    List<Space> spacesList = remoteSpaces.GetOneSpace(spaceId);
    } catch (EIssueException ex) {
    Logger.getLogger(PanelBookings.class.getName()).log(Level.SEVERE, null, ex);
    }
    
    }*/
    /*   private void newFilter()
    {
    RowFilter<TableModelResources, Object> rf = null; 
    //declare a row filter for your table model
    try{
    rf = RowFilter.regexFilter("^" + jtfSearch.getText(), 0);  
    //initialize with a regular expression
    } catch (java.util.regex.PatternSyntaxException e){
    return;
    }
    sorter.setRowFilter(rf);
    }*/
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PanelBookings.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PanelBookings.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PanelBookings.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PanelBookings.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new PanelBookings(Boolean.TRUE).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnCancelBooking;
    private javax.swing.JButton btnPay;
    private javax.swing.JButton jButtonFilter;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JComboBox jcmbUser;
    private javax.swing.JTextField jtxtFrom;
    private javax.swing.JTextField jtxtTo;
    private javax.swing.JTable tblBookingSpaces;
    private javax.swing.JTextField txtTotalAmount;
    // End of variables declaration//GEN-END:variables
}

class TableModelBookings extends AbstractTableModel {

    List bookingsList;
    String headerList[] = new String[]{"BookingId", "User", "Space", "Start_time", "End_time", "Status"};

    public TableModelBookings(List list) {
        bookingsList = list;
    }

    @Override
    public int getColumnCount() {
        return 6;
    }

    @Override
    public int getRowCount() {
        return bookingsList.size();
    }
    // this method is called to set the value of each cell

    @Override
    public Object getValueAt(int row, int col) {
        Object returnValue = false;
        Booking entity = (Booking) bookingsList.get(row);
        switch (col) {
            case 0:
                returnValue = entity.getBookingid();
                break;
            case 1:
                returnValue = entity.getUser();
                break;
            case 2:
                returnValue = entity.getSpace();
                break;
            case 3:
                returnValue = entity.getStart_time();
                break;
            case 4:
                returnValue = entity.getEnd_time();
                break;
            case 5:
                returnValue = entity.getStatus();
                break;

        }
        return returnValue;
    }
    //display the name of columns

    @Override
    public String getColumnName(int col) {
        return headerList[col];
    }
}

class TableModelResources extends AbstractTableModel {

    List bookingResourcesList;
    String headerList[] = new String[]{"ResourceId", "Descripcio", "Amount"};

    public TableModelResources(List list) {
        bookingResourcesList = list;
    }

    @Override
    public int getColumnCount() {
        return headerList.length;
    }

    @Override
    public int getRowCount() {
        return bookingResourcesList.size();
    }
    // this method is called to set the value of each cell

    @Override
    public Object getValueAt(int row, int col) {
        Object returnValue = false;
        Resource entity = (Resource) bookingResourcesList.get(row);
        switch (col) {
            case 0:
                returnValue = entity.getResourceId();
                break;
            case 1:
                returnValue = entity.getResourceDescription();
                break;
            case 2:
                returnValue = entity.getAmount();
                break;
        }
        return returnValue;
    }
    //display the name of columns

    @Override
    public String getColumnName(int col) {
        return headerList[col];
    }
    /*void removeRow(int i) {
    throw new UnsupportedOperationException("Not yet implemented");
    bookingResourcesList.remove(i);
    }
    void clean(int i) {
    throw new UnsupportedOperationException("Not yet implemented");
    bookingResourcesList.removeAll(bookingResourcesList);
    
    }*/
}